package com.china.api.web.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.china.itapi.common.entity.CustomerEntity;



@Controller
@RequestMapping("/test")
public class TestController extends GenericController {


	@InitBinder("user")
	public void initBinder1(WebDataBinder binder) {
		System.out.println("44444444444444");
		binder.setFieldDefaultPrefix("user.");
		CustomerEntity ce = new CustomerEntity();
	}
	
	@InitBinder("sb")
	public void initBinder2(WebDataBinder binder) {
		System.out.println("sbsbsbsbsbsbsbsb");
		binder.setFieldDefaultPrefix("sb.");
	}

	@RequestMapping(value = "/user", method = RequestMethod.POST)
	@ResponseBody
	public String test(@ModelAttribute("sb")User user, Address addr, HttpServletResponse response, Model model) throws IOException {
		Map<String, Object> map = model.asMap();
		return "test";
	}

	static class User {
		private String name;
		private String passwd;
		private Address addr = new Address();

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}

		public String getPasswd() {
			return passwd;
		}

		public void setPasswd(String passwd) {
			this.passwd = passwd;
		}

		public Address getAddr() {
			return addr;
		}

		public void setAddr(Address addr) {
			this.addr = addr;
		}

	}

	static class Address {
		private String country;
		private String city;

		public String getCountry() {
			return country;
		}

		public void setCountry(String country) {
			this.country = country;
		}

		public String getCity() {
			return city;
		}

		public void setCity(String city) {
			this.city = city;
		}
	}
}
